<template>
  <div :id="echartId" class="echarts"></div>
</template>

<script>
import { makeId } from "@/utils";
import echarts from "echarts";
export default {
  name: "EchartWrapper",
  props: {
    option: {
      type: Object,
      default: null
    },
    clickHandle: {
      type: Function,
      default: null
    }
  },
  data() {
    return {
      echartId: "echart-" + makeId(12),
      echart: null
    };
  },
  watch: {
    option: {
      handler(v) {
        this.echart.setOption(this.option, true);
      },
      deep: true
    }
  },
  mounted() {
    this.echart = echarts.init(document.getElementById(this.echartId));
    this.clickHandle && this.echart.on("click", this.clickHandle);
    this.echart.setOption(this.option);
  }
};
</script>

<style lang="scss" scoped>
.echart-wrapper {
  width: 100%;
  height: 100%;
}
</style>
